package com.zut.controller.adminshop;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.zut.pojo.PageInfo;
import com.zut.pojo.Shop;
import com.zut.service.AdminShopService;
import com.zut.service.impl.AdminShopServiceImpl;
import com.zut.vo.ShopVo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author 张晨
 * @date 2024/9/6 15:58
 * @desc
 */

@WebServlet("/adminshop/select")
public class AdminShopSelectController extends HttpServlet {
    private AdminShopService adminShopService= new AdminShopServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String currentPage = req.getParameter("currentPage");
        String pageSize = req.getParameter("pageSize");

        if (StringUtils.isEmpty(currentPage)){
            currentPage = "1";
        }
        if (StringUtils.isEmpty(pageSize)){
            pageSize = "5";
        }

        String shopName = req.getParameter("shopName");

        String status = req.getParameter("status");

        Shop shop = new Shop();

        shop.setShopName(shopName);

        if (status != null){
            shop.setStatus(Integer.parseInt(status));
        }


        PageInfo<ShopVo> AdminShop = adminShopService.selectAll(shop,Integer.parseInt(currentPage),Integer.parseInt(pageSize));

        String jsonString = JSON.toJSONString(AdminShop);

        resp.getWriter().write(jsonString);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
